package com.jacobson.core.widget.security.authc.credential

import com.jacobson.core.widget.security.authc.AuthenticationInfo
import com.jacobson.core.widget.security.authc.AuthenticationToken

/**
 * ================================================
 *  简单证书匹配器。Object.equals
 *  @author Wucz on 2018/8/7 16:33
 * ================================================
 */
class SimpleCredentialsMatcher : CredentialsMatcher {
    override fun doCredentialsMatch(token: AuthenticationToken, info: AuthenticationInfo): Boolean {
        val tokenCredentials = token.credentials
        val accountCredentials = info.credentials
        return this.equals(tokenCredentials, accountCredentials)
    }

    private fun equals(tokenCredentials: Any?, accountCredentials: Any?): Boolean {
        return tokenCredentials?.equals(accountCredentials) ?: accountCredentials == null
    }
}